function PageBackendUser(user, sd, options) {
  this._user = user;
  this._sd = sd;
  this._options = (options) ? options : null;
  
  this._gui = { navigation: document.getElementById('img1'),
                naviStatus: document.getElementById('td1'),
                account: document.getElementById('input1'),
                email: document.getElementById('input2'),
                password: document.getElementById('input3'),
                type: document.getElementById('input4'),
                photographer: { pRate: document.getElementById('table1'),
                                photographer: document.getElementById('input5'),
                                pWedding: document.getElementById('input6'),
                                pPrewedding: document.getElementById('input7'),
                                pPortrait: document.getElementById('input8'),
                                pEngagement: document.getElementById('input9')
                              },
                videographer: { vRate: document.getElementById('table2'),
                                videographer: document.getElementById('input10'),
                                vWedding: document.getElementById('input11'),
                                vPrewedding: document.getElementById('input12'),
                                vPortrait: document.getElementById('input13'),
                                vEngagement: document.getElementById('input14')
                              },
                makeup: { mRate: document.getElementById('table3'),
                          makeup: document.getElementById('input15'),
                          mHouse: document.getElementById('input16'),
                          mStudio: document.getElementById('input17'),
                          mFullDay: document.getElementById('input18')
                        },
                btnBack: document.getElementById('img2'),
                btnSave: document.getElementById('img3')
              };
  
  this._gui.type.options[this._gui.type.options.length] = new Option('');
  for (var i = 0, il = UserType.array().length; i < il; i++) {
    var type = UserType.array()[i];
    if (type.charAt(0) == '#' || type.charAt(0) == '*') {
      continue;
    }
    option = new Option(type);
    this._gui.type.options[this._gui.type.options.length] = option;
  }
  
  this._createElements();
};

PageBackendUser.prototype._createElements = function() {
  var a, tr, td, _self = this;
  
  this._gui.navigation.onclick = function() { location.href = '?p=pageasst&t=pagebackendusers&m1=a4&m2=b1'; };
  DOMUtils.removeChildElements(this._gui.naviStatus);
  var img = document.createElement('img');
  if (this._options.uid) {
    img.src = 'images/pageasst/pagebackenduser/edituser.png';
  } else {
    img.src = 'images/pageasst/pagebackenduser/addnewuser.png';
  }
  this._gui.naviStatus.appendChild(img);
  
  this._loadData();
};

PageBackendUser.prototype._loadData = function() {
  this._user = null;
  this._retrieveUser();
};

PageBackendUser.prototype._verifyData = function() {
  if (this._user) {
    this._updateElements();
  }
};

PageBackendUser.prototype._retrieveUser = function() {
  var _self = this;
  if (this._options.uid) {
    new RequestUtils()._read('user', null, 'd.oid = ' + this._options.uid, null, null, null, null, function(result, params) { _self._user = (result.data.length == 1) ? result.data[0] : null;
                                                                                                                              _self._verifyData.call(_self);
                                                                                                                            }, null);
  } else {
    this._user = User.instance();
    this._verifyData();
  }
};

PageBackendUser.prototype._updateElements = function() {
  var table, tr, td, _self = this;
  
  if (!this._user.attribute) {
    this._user.attribute = UserAttribute.instance();
  }

  this._gui.account.value = this._user.account;
  this._gui.email.value = this._user.email;
  this._gui.password.value = this._user.password;
  for (var i = 0, il = this._gui.type.options.length; i < il; i++) {
    var option = this._gui.type.options[i];
    if (option.text == this._user.type) {
      this._gui.type.selectedIndex = i;
    }
  }
  
  this._gui.photographer.photographer.checked = this._user.attribute.pEnabled;
  this._gui.videographer.videographer.checked = this._user.attribute.vEnabled;
  this._gui.makeup.makeup.checked = this._user.attribute.mEnabled;
  
  this._gui.photographer.pWedding.value = this._user.attribute.pWedding;
  this._gui.photographer.pPrewedding.value = this._user.attribute.pPrewedding;
  this._gui.photographer.pPortrait.value = this._user.attribute.pPortrait;
  this._gui.photographer.pEngagement.value = this._user.attribute.pEngagement;
  this._gui.videographer.vWedding.value = this._user.attribute.vWedding;
  this._gui.videographer.vPrewedding.value = this._user.attribute.vPrewedding;
  this._gui.videographer.vPortrait.value = this._user.attribute.vPortrait;
  this._gui.videographer.vEngagement.value = this._user.attribute.vEngagement;
  this._gui.makeup.mHouse.value = this._user.attribute.mHouse;
  this._gui.makeup.mStudio.value = this._user.attribute.mStudio;
  this._gui.makeup.mFullDay.value = this._user.attribute.mFullDay;
  
  if (this._user.attribute.pEnabled) {
    this._gui.photographer.pRate.style.display = 'block';
  } else {
    this._gui.photographer.pRate.style.display = 'none';
  }
  if (this._user.attribute.vEnabled) {
    this._gui.videographer.vRate.style.display = 'block';
  } else {
    this._gui.videographer.vRate.style.display = 'none';
  }
  if (this._user.attribute.mEnabled) {
    this._gui.makeup.mRate.style.display = 'block';
  } else {
    this._gui.makeup.mRate.style.display = 'none';
  }
  
  this._gui.account.onchange = function() { _self._user.account = this.value; };
  this._gui.email.onchange = function() { _self._user.email = this.value; };
  this._gui.password.onchange = function() { _self._user.password = this.value; };
  this._gui.type.onchange = function() { _self._user.type = this.options[this.selectedIndex].text; };
  this._gui.photographer.photographer.onchange = function() { if (_self._gui.photographer.photographer.checked) {
                                                                _self._user.attribute.pEnabled = true;
                                                                _self._updateElements.call(_self);
                                                              } else {
                                                                _self._user.attribute.pEnabled = false;
                                                                _self._user.attribute.pWedding = 0;
                                                                _self._user.attribute.pPrewedding = 0;
                                                                _self._user.attribute.pPortrait = 0;
                                                                _self._user.attribute.pEngagement = 0;
                                                                _self._updateElements.call(_self);
                                                              }
                                                            };
  this._gui.videographer.videographer.onchange = function() { if (_self._gui.videographer.videographer.checked) {
                                                                _self._user.attribute.vEnabled = true;
                                                                _self._updateElements.call(_self);
                                                              } else {
                                                                _self._user.attribute.vEnabled = false;
                                                                _self._user.attribute.vWedding = 0;
                                                                _self._user.attribute.vPrewedding = 0;
                                                                _self._user.attribute.vPortrait = 0;
                                                                _self._user.attribute.vEngagement = 0;
                                                                _self._updateElements.call(_self);
                                                              }
                                                            };
  this._gui.makeup.makeup.onchange = function() { if (_self._gui.makeup.makeup.checked) {
                                                    _self._user.attribute.mEnabled = true;
                                                    _self._updateElements.call(_self);
                                                  } else {
                                                    _self._user.attribute.mEnabled = false;
                                                    _self._user.attribute.mHouse = 0; 
                                                    _self._user.attribute.mStudio = 0;
                                                    _self._user.attribute.mFullDay = 0;
                                                    _self._updateElements.call(_self);
                                                  }
                                                };

  this._gui.photographer.pWedding.onchange = function() { _self._user.attribute.pWedding = this.value; };
  this._gui.photographer.pPrewedding.onchange = function() { _self._user.attribute.pPrewedding = this.value; };
  this._gui.photographer.pPortrait.onchange = function() { _self._user.attribute.pPortrait = this.value; };
  this._gui.photographer.pEngagement.onchange = function() { _self._user.attribute.pEngagement = this.value; };
  this._gui.videographer.vWedding.onchange = function() { _self._user.attribute.vWedding = this.value; };
  this._gui.videographer.vPrewedding.onchange = function() { _self._user.attribute.vPrewedding = this.value; };
  this._gui.videographer.vPortrait.onchange = function() { _self._user.attribute.vPortrait = this.value; };
  this._gui.videographer.vEngagement.onchange = function() { _self._user.attribute.vEngagement = this.value; };
  this._gui.makeup.mHouse.onchange = function() { _self._user.attribute.mHouse = this.value; };
  this._gui.makeup.mStudio.onchange = function() { _self._user.attribute.mStudio = this.value; };
  this._gui.makeup.mFullDay.onchange = function() { _self._user.attribute.mFullDay = this.value; };
  
  this._gui.btnSave.onclick = function() { new RequestUtils()._write('user', [_self._user], [], function() { location.href = '?p=pageasst&t=pagebackendusers&m1=a4&m2=b1'; }, null); };
  
  this._gui.btnBack.onclick = function() { location.href = '?p=pageasst&t=pagebackendusers&m1=a4&m2=b1'; };
};
